{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 选择列\n",
    "## 选择指定的一列或多列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import tushare as ts\n",
    "\n",
    "df = ts.get_stock_basics()\n",
    "# df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>industry</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>code</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>300785</th>\n",
       "      <td>N值得买</td>\n",
       "      <td>互联网</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>002105</th>\n",
       "      <td>信隆健康</td>\n",
       "      <td>文教休闲</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>002453</th>\n",
       "      <td>华软科技</td>\n",
       "      <td>软件服务</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>300167</th>\n",
       "      <td>迪威迅</td>\n",
       "      <td>通信设备</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>600078</th>\n",
       "      <td>澄星股份</td>\n",
       "      <td>化工原料</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        name industry\n",
       "code                 \n",
       "300785  N值得买      互联网\n",
       "002105  信隆健康     文教休闲\n",
       "002453  华软科技     软件服务\n",
       "300167   迪威迅     通信设备\n",
       "600078  澄星股份     化工原料"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 普通索引\n",
    "df[[\"name\",\"industry\"]].head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>area</th>\n",
       "      <th>totalAssets</th>\n",
       "      <th>fixedAssets</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>code</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>300785</th>\n",
       "      <td>N值得买</td>\n",
       "      <td>北京</td>\n",
       "      <td>48764.53</td>\n",
       "      <td>19884.82</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>002105</th>\n",
       "      <td>信隆健康</td>\n",
       "      <td>深圳</td>\n",
       "      <td>154854.75</td>\n",
       "      <td>52288.67</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>002453</th>\n",
       "      <td>华软科技</td>\n",
       "      <td>江苏</td>\n",
       "      <td>284480.44</td>\n",
       "      <td>33179.48</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>300167</th>\n",
       "      <td>迪威迅</td>\n",
       "      <td>深圳</td>\n",
       "      <td>101689.36</td>\n",
       "      <td>2198.40</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>600078</th>\n",
       "      <td>澄星股份</td>\n",
       "      <td>江苏</td>\n",
       "      <td>780936.56</td>\n",
       "      <td>249314.55</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        name area  totalAssets  fixedAssets\n",
       "code                                       \n",
       "300785  N值得买   北京     48764.53     19884.82\n",
       "002105  信隆健康   深圳    154854.75     52288.67\n",
       "002453  华软科技   江苏    284480.44     33179.48\n",
       "300167   迪威迅   深圳    101689.36      2198.40\n",
       "600078  澄星股份   江苏    780936.56    249314.55"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 位置索引\n",
    "df.iloc[:,[0,2,6,8]].head() # [index, columns]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>area</th>\n",
       "      <th>totalAssets</th>\n",
       "      <th>fixedAssets</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>code</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>002473</th>\n",
       "      <td>圣莱达</td>\n",
       "      <td>浙江</td>\n",
       "      <td>35527.93</td>\n",
       "      <td>2252.06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>002225</th>\n",
       "      <td>濮耐股份</td>\n",
       "      <td>河南</td>\n",
       "      <td>552356.25</td>\n",
       "      <td>63030.76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>300527</th>\n",
       "      <td>中国应急</td>\n",
       "      <td>湖北</td>\n",
       "      <td>420055.59</td>\n",
       "      <td>43275.78</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        name area  totalAssets  fixedAssets\n",
       "code                                       \n",
       "002473   圣莱达   浙江     35527.93      2252.06\n",
       "002225  濮耐股份   河南    552356.25     63030.76\n",
       "300527  中国应急   湖北    420055.59     43275.78"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 获取指定的行和列\n",
    "df.iloc[[5,6,9],[0,2,6,8]].head() # [index, columns]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>area</th>\n",
       "      <th>totalAssets</th>\n",
       "      <th>fixedAssets</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>code</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>002473</th>\n",
       "      <td>圣莱达</td>\n",
       "      <td>浙江</td>\n",
       "      <td>35527.93</td>\n",
       "      <td>2252.06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>300527</th>\n",
       "      <td>中国应急</td>\n",
       "      <td>湖北</td>\n",
       "      <td>420055.59</td>\n",
       "      <td>43275.78</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        name area  totalAssets  fixedAssets\n",
       "code                                       \n",
       "002473   圣莱达   浙江     35527.93      2252.06\n",
       "300527  中国应急   湖北    420055.59     43275.78"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 获取指定的行和列\n",
    "df.iloc[[5,9],[0,2,6,8]].head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 获取连续的多列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>industry</th>\n",
       "      <th>area</th>\n",
       "      <th>pe</th>\n",
       "      <th>outstanding</th>\n",
       "      <th>totals</th>\n",
       "      <th>totalAssets</th>\n",
       "      <th>liquidAssets</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>code</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>300785</th>\n",
       "      <td>N值得买</td>\n",
       "      <td>互联网</td>\n",
       "      <td>北京</td>\n",
       "      <td>30.07</td>\n",
       "      <td>0.13</td>\n",
       "      <td>0.53</td>\n",
       "      <td>48764.53</td>\n",
       "      <td>27498.36</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>002105</th>\n",
       "      <td>信隆健康</td>\n",
       "      <td>文教休闲</td>\n",
       "      <td>深圳</td>\n",
       "      <td>0.00</td>\n",
       "      <td>3.69</td>\n",
       "      <td>3.69</td>\n",
       "      <td>154854.75</td>\n",
       "      <td>86097.10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>002453</th>\n",
       "      <td>华软科技</td>\n",
       "      <td>软件服务</td>\n",
       "      <td>江苏</td>\n",
       "      <td>190.10</td>\n",
       "      <td>5.55</td>\n",
       "      <td>5.71</td>\n",
       "      <td>284480.44</td>\n",
       "      <td>147371.98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>300167</th>\n",
       "      <td>迪威迅</td>\n",
       "      <td>通信设备</td>\n",
       "      <td>深圳</td>\n",
       "      <td>0.00</td>\n",
       "      <td>3.00</td>\n",
       "      <td>3.00</td>\n",
       "      <td>101689.36</td>\n",
       "      <td>59433.01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>600078</th>\n",
       "      <td>澄星股份</td>\n",
       "      <td>化工原料</td>\n",
       "      <td>江苏</td>\n",
       "      <td>126.12</td>\n",
       "      <td>6.63</td>\n",
       "      <td>6.63</td>\n",
       "      <td>780936.56</td>\n",
       "      <td>391236.94</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        name industry area      pe  outstanding  totals  totalAssets  \\\n",
       "code                                                                   \n",
       "300785  N值得买      互联网   北京   30.07         0.13    0.53     48764.53   \n",
       "002105  信隆健康     文教休闲   深圳    0.00         3.69    3.69    154854.75   \n",
       "002453  华软科技     软件服务   江苏  190.10         5.55    5.71    284480.44   \n",
       "300167   迪威迅     通信设备   深圳    0.00         3.00    3.00    101689.36   \n",
       "600078  澄星股份     化工原料   江苏  126.12         6.63    6.63    780936.56   \n",
       "\n",
       "        liquidAssets  \n",
       "code                  \n",
       "300785      27498.36  \n",
       "002105      86097.10  \n",
       "002453     147371.98  \n",
       "300167      59433.01  \n",
       "600078     391236.94  "
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 获取第1列到第9列的数据\n",
    "df.iloc[:,0:8].head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 选择行\n",
    "\n",
    "## 选择指定的一行或多行\n",
    "### 普通索引  \n",
    "使用loc方法。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "name                    三泰控股\n",
       "industry                电脑设备\n",
       "area                      四川\n",
       "pe                         0\n",
       "outstanding             9.87\n",
       "totals                 13.78\n",
       "totalAssets           343245\n",
       "liquidAssets          207733\n",
       "fixedAssets          18278.8\n",
       "reserved              283996\n",
       "reservedPerShare        2.06\n",
       "esp                   -0.026\n",
       "bvps                    2.31\n",
       "pb                      1.71\n",
       "timeToMarket        20091203\n",
       "undp                 -105368\n",
       "perundp                -0.76\n",
       "rev                     14.1\n",
       "profit                 59.43\n",
       "gpr                     6.46\n",
       "npr                   -18.93\n",
       "holders                80000\n",
       "Name: 002312, dtype: object"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[\"002312\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>industry</th>\n",
       "      <th>area</th>\n",
       "      <th>pe</th>\n",
       "      <th>outstanding</th>\n",
       "      <th>totals</th>\n",
       "      <th>totalAssets</th>\n",
       "      <th>liquidAssets</th>\n",
       "      <th>fixedAssets</th>\n",
       "      <th>reserved</th>\n",
       "      <th>...</th>\n",
       "      <th>bvps</th>\n",
       "      <th>pb</th>\n",
       "      <th>timeToMarket</th>\n",
       "      <th>undp</th>\n",
       "      <th>perundp</th>\n",
       "      <th>rev</th>\n",
       "      <th>profit</th>\n",
       "      <th>gpr</th>\n",
       "      <th>npr</th>\n",
       "      <th>holders</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>code</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>002312</th>\n",
       "      <td>三泰控股</td>\n",
       "      <td>电脑设备</td>\n",
       "      <td>四川</td>\n",
       "      <td>0.0</td>\n",
       "      <td>9.87</td>\n",
       "      <td>13.78</td>\n",
       "      <td>343244.63</td>\n",
       "      <td>207733.41</td>\n",
       "      <td>18278.77</td>\n",
       "      <td>283996.47</td>\n",
       "      <td>...</td>\n",
       "      <td>2.31</td>\n",
       "      <td>1.71</td>\n",
       "      <td>20091203</td>\n",
       "      <td>-105368.40</td>\n",
       "      <td>-0.76</td>\n",
       "      <td>14.10</td>\n",
       "      <td>59.43</td>\n",
       "      <td>6.46</td>\n",
       "      <td>-18.93</td>\n",
       "      <td>80000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>002432</th>\n",
       "      <td>九安医疗</td>\n",
       "      <td>医疗保健</td>\n",
       "      <td>天津</td>\n",
       "      <td>0.0</td>\n",
       "      <td>4.33</td>\n",
       "      <td>4.33</td>\n",
       "      <td>186362.56</td>\n",
       "      <td>85589.53</td>\n",
       "      <td>20250.18</td>\n",
       "      <td>128757.71</td>\n",
       "      <td>...</td>\n",
       "      <td>3.49</td>\n",
       "      <td>1.84</td>\n",
       "      <td>20100610</td>\n",
       "      <td>-24471.63</td>\n",
       "      <td>-0.57</td>\n",
       "      <td>25.24</td>\n",
       "      <td>-40.17</td>\n",
       "      <td>31.44</td>\n",
       "      <td>-23.33</td>\n",
       "      <td>67600.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>2 rows × 22 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        name industry area   pe  outstanding  totals  totalAssets  \\\n",
       "code                                                                \n",
       "002312  三泰控股     电脑设备   四川  0.0         9.87   13.78    343244.63   \n",
       "002432  九安医疗     医疗保健   天津  0.0         4.33    4.33    186362.56   \n",
       "\n",
       "        liquidAssets  fixedAssets   reserved   ...     bvps    pb  \\\n",
       "code                                           ...                  \n",
       "002312     207733.41     18278.77  283996.47   ...     2.31  1.71   \n",
       "002432      85589.53     20250.18  128757.71   ...     3.49  1.84   \n",
       "\n",
       "        timeToMarket       undp  perundp    rev  profit    gpr    npr  holders  \n",
       "code                                                                            \n",
       "002312      20091203 -105368.40    -0.76  14.10   59.43   6.46 -18.93  80000.0  \n",
       "002432      20100610  -24471.63    -0.57  25.24  -40.17  31.44 -23.33  67600.0  \n",
       "\n",
       "[2 rows x 22 columns]"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[[\"002312\",\"002432\"]]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 位置索引\n",
    "使用iloc方法()。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "name                    N值得买\n",
       "industry                 互联网\n",
       "area                      北京\n",
       "pe                     30.07\n",
       "outstanding             0.13\n",
       "totals                  0.53\n",
       "totalAssets          48764.5\n",
       "liquidAssets         27498.4\n",
       "fixedAssets          19884.8\n",
       "reserved             9259.55\n",
       "reservedPerShare        1.74\n",
       "esp                     0.34\n",
       "bvps                    8.65\n",
       "pb                      4.73\n",
       "timeToMarket        20190715\n",
       "undp                 19231.9\n",
       "perundp                 3.61\n",
       "rev                        0\n",
       "profit                     0\n",
       "gpr                    73.69\n",
       "npr                    17.55\n",
       "holders                26665\n",
       "Name: 300785, dtype: object"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 选择第一行\n",
    "df.iloc[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>industry</th>\n",
       "      <th>area</th>\n",
       "      <th>pe</th>\n",
       "      <th>outstanding</th>\n",
       "      <th>totals</th>\n",
       "      <th>totalAssets</th>\n",
       "      <th>liquidAssets</th>\n",
       "      <th>fixedAssets</th>\n",
       "      <th>reserved</th>\n",
       "      <th>...</th>\n",
       "      <th>bvps</th>\n",
       "      <th>pb</th>\n",
       "      <th>timeToMarket</th>\n",
       "      <th>undp</th>\n",
       "      <th>perundp</th>\n",
       "      <th>rev</th>\n",
       "      <th>profit</th>\n",
       "      <th>gpr</th>\n",
       "      <th>npr</th>\n",
       "      <th>holders</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>code</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>300785</th>\n",
       "      <td>N值得买</td>\n",
       "      <td>互联网</td>\n",
       "      <td>北京</td>\n",
       "      <td>30.07</td>\n",
       "      <td>0.13</td>\n",
       "      <td>0.53</td>\n",
       "      <td>48764.53</td>\n",
       "      <td>27498.36</td>\n",
       "      <td>19884.82</td>\n",
       "      <td>9259.55</td>\n",
       "      <td>...</td>\n",
       "      <td>8.65</td>\n",
       "      <td>4.73</td>\n",
       "      <td>20190715</td>\n",
       "      <td>19231.93</td>\n",
       "      <td>3.61</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>73.69</td>\n",
       "      <td>17.55</td>\n",
       "      <td>26665.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>002453</th>\n",
       "      <td>华软科技</td>\n",
       "      <td>软件服务</td>\n",
       "      <td>江苏</td>\n",
       "      <td>190.10</td>\n",
       "      <td>5.55</td>\n",
       "      <td>5.71</td>\n",
       "      <td>284480.44</td>\n",
       "      <td>147371.98</td>\n",
       "      <td>33179.48</td>\n",
       "      <td>34071.73</td>\n",
       "      <td>...</td>\n",
       "      <td>1.59</td>\n",
       "      <td>3.92</td>\n",
       "      <td>20100720</td>\n",
       "      <td>-3918.70</td>\n",
       "      <td>-0.07</td>\n",
       "      <td>128.21</td>\n",
       "      <td>2.36</td>\n",
       "      <td>10.20</td>\n",
       "      <td>0.83</td>\n",
       "      <td>37258.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>300527</th>\n",
       "      <td>中国应急</td>\n",
       "      <td>专用机械</td>\n",
       "      <td>湖北</td>\n",
       "      <td>459.76</td>\n",
       "      <td>2.66</td>\n",
       "      <td>9.14</td>\n",
       "      <td>420055.59</td>\n",
       "      <td>325186.13</td>\n",
       "      <td>43275.78</td>\n",
       "      <td>40946.25</td>\n",
       "      <td>...</td>\n",
       "      <td>2.25</td>\n",
       "      <td>5.95</td>\n",
       "      <td>20160805</td>\n",
       "      <td>67714.97</td>\n",
       "      <td>0.74</td>\n",
       "      <td>0.69</td>\n",
       "      <td>30.82</td>\n",
       "      <td>18.81</td>\n",
       "      <td>2.03</td>\n",
       "      <td>46295.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>3 rows × 22 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        name industry area      pe  outstanding  totals  totalAssets  \\\n",
       "code                                                                   \n",
       "300785  N值得买      互联网   北京   30.07         0.13    0.53     48764.53   \n",
       "002453  华软科技     软件服务   江苏  190.10         5.55    5.71    284480.44   \n",
       "300527  中国应急     专用机械   湖北  459.76         2.66    9.14    420055.59   \n",
       "\n",
       "        liquidAssets  fixedAssets  reserved   ...     bvps    pb  \\\n",
       "code                                          ...                  \n",
       "300785      27498.36     19884.82   9259.55   ...     8.65  4.73   \n",
       "002453     147371.98     33179.48  34071.73   ...     1.59  3.92   \n",
       "300527     325186.13     43275.78  40946.25   ...     2.25  5.95   \n",
       "\n",
       "        timeToMarket      undp  perundp     rev  profit    gpr    npr  holders  \n",
       "code                                                                            \n",
       "300785      20190715  19231.93     3.61    0.00    0.00  73.69  17.55  26665.0  \n",
       "002453      20100720  -3918.70    -0.07  128.21    2.36  10.20   0.83  37258.0  \n",
       "300527      20160805  67714.97     0.74    0.69   30.82  18.81   2.03  46295.0  \n",
       "\n",
       "[3 rows x 22 columns]"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.iloc[[0,2,9]]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 选择连续的多行\n",
    "使用iloc方法()。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>industry</th>\n",
       "      <th>area</th>\n",
       "      <th>pe</th>\n",
       "      <th>outstanding</th>\n",
       "      <th>totals</th>\n",
       "      <th>totalAssets</th>\n",
       "      <th>liquidAssets</th>\n",
       "      <th>fixedAssets</th>\n",
       "      <th>reserved</th>\n",
       "      <th>...</th>\n",
       "      <th>bvps</th>\n",
       "      <th>pb</th>\n",
       "      <th>timeToMarket</th>\n",
       "      <th>undp</th>\n",
       "      <th>perundp</th>\n",
       "      <th>rev</th>\n",
       "      <th>profit</th>\n",
       "      <th>gpr</th>\n",
       "      <th>npr</th>\n",
       "      <th>holders</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>code</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>300785</th>\n",
       "      <td>N值得买</td>\n",
       "      <td>互联网</td>\n",
       "      <td>北京</td>\n",
       "      <td>30.07</td>\n",
       "      <td>0.13</td>\n",
       "      <td>0.53</td>\n",
       "      <td>48764.53</td>\n",
       "      <td>27498.36</td>\n",
       "      <td>19884.82</td>\n",
       "      <td>9259.55</td>\n",
       "      <td>...</td>\n",
       "      <td>8.65</td>\n",
       "      <td>4.73</td>\n",
       "      <td>20190715</td>\n",
       "      <td>19231.93</td>\n",
       "      <td>3.61</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>73.69</td>\n",
       "      <td>17.55</td>\n",
       "      <td>26665.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>002105</th>\n",
       "      <td>信隆健康</td>\n",
       "      <td>文教休闲</td>\n",
       "      <td>深圳</td>\n",
       "      <td>0.00</td>\n",
       "      <td>3.69</td>\n",
       "      <td>3.69</td>\n",
       "      <td>154854.75</td>\n",
       "      <td>86097.10</td>\n",
       "      <td>52288.67</td>\n",
       "      <td>5235.16</td>\n",
       "      <td>...</td>\n",
       "      <td>1.36</td>\n",
       "      <td>3.61</td>\n",
       "      <td>20070112</td>\n",
       "      <td>1758.42</td>\n",
       "      <td>0.05</td>\n",
       "      <td>4.48</td>\n",
       "      <td>-33.50</td>\n",
       "      <td>12.64</td>\n",
       "      <td>-2.11</td>\n",
       "      <td>28205.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>002453</th>\n",
       "      <td>华软科技</td>\n",
       "      <td>软件服务</td>\n",
       "      <td>江苏</td>\n",
       "      <td>190.10</td>\n",
       "      <td>5.55</td>\n",
       "      <td>5.71</td>\n",
       "      <td>284480.44</td>\n",
       "      <td>147371.98</td>\n",
       "      <td>33179.48</td>\n",
       "      <td>34071.73</td>\n",
       "      <td>...</td>\n",
       "      <td>1.59</td>\n",
       "      <td>3.92</td>\n",
       "      <td>20100720</td>\n",
       "      <td>-3918.70</td>\n",
       "      <td>-0.07</td>\n",
       "      <td>128.21</td>\n",
       "      <td>2.36</td>\n",
       "      <td>10.20</td>\n",
       "      <td>0.83</td>\n",
       "      <td>37258.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>3 rows × 22 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        name industry area      pe  outstanding  totals  totalAssets  \\\n",
       "code                                                                   \n",
       "300785  N值得买      互联网   北京   30.07         0.13    0.53     48764.53   \n",
       "002105  信隆健康     文教休闲   深圳    0.00         3.69    3.69    154854.75   \n",
       "002453  华软科技     软件服务   江苏  190.10         5.55    5.71    284480.44   \n",
       "\n",
       "        liquidAssets  fixedAssets  reserved   ...     bvps    pb  \\\n",
       "code                                          ...                  \n",
       "300785      27498.36     19884.82   9259.55   ...     8.65  4.73   \n",
       "002105      86097.10     52288.67   5235.16   ...     1.36  3.61   \n",
       "002453     147371.98     33179.48  34071.73   ...     1.59  3.92   \n",
       "\n",
       "        timeToMarket      undp  perundp     rev  profit    gpr    npr  holders  \n",
       "code                                                                            \n",
       "300785      20190715  19231.93     3.61    0.00    0.00  73.69  17.55  26665.0  \n",
       "002105      20070112   1758.42     0.05    4.48  -33.50  12.64  -2.11  28205.0  \n",
       "002453      20100720  -3918.70    -0.07  128.21    2.36  10.20   0.83  37258.0  \n",
       "\n",
       "[3 rows x 22 columns]"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 选择第1行到第3行\n",
    "df.iloc[0:3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
